﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;
using FineUIPro;

namespace CanDoo.Oil.WebApp.cusSupplier
{
    public partial class Default : ListPageBase<ISupplierContract, Supplier>
    {


        public ISupplierTypeContract SupplierTypeContract { get; set; }
        public IWarehouseContract WarehouseContract { get; set; }

        #region 方法
        protected override void InitGrid()
        {
            Selector = p => new
            {
                p.Code,
                p.ShortName,
                p.SupplierType,
                p.SupplierTypeId,
                p.Tel,
                p.Mobile,
                p.QQ,
                p.WebChat,
                p.WebSite,
                p.Fax,
                p.LegalPerson,
                p.Warehouse,
                p.WarehouseId,
                p.RegMoney,
                p.Address,
                p.License,
                p.Enable,
                p.AccountPeriod,
                p.Remark,
                p.Id,
                p.Name
            };
            base.InitGrid();
        }

        protected override void Search()
        {
            var key = SearchKey.GetValue();
            var suppliertypeId = SearchSupplierType.GetValue().ToLong();
            if(string.IsNullOrEmpty(key) == false)
            {
                Filter = Filter.And(p => p.Name.Contains(key) || p.Code.Contains(key) || p.ShortName.Contains(key) || p.Tel.Contains(key) || p.Mobile.Contains(key));
            }
            if (suppliertypeId >  0L)
                Filter = Filter.And(p => p.SupplierTypeId == suppliertypeId);

            var isDeleted = ManageRecycle.Checked;
            Filter = Filter.And(p => p.IsDeleted == isDeleted);
        }
        #endregion

        #region 事件
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FineUIListHelper.BindDDL(SupplierTypeContract.EntityName, this.SupplierTypeContract.GetSelectList(), 0L, SearchSupplierType);
                InitGrid();
            }
        }
        #endregion

        #endregion 事件

    }
}
